<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .hide {
            display: none;
        }

        .c1 {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .5);
            z-index: 2;
        }

        .c2 {
            background-color: white;
            position: fixed;
            width: 400px;
            height: 300px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -200px;
            padding-top: 2%;
            padding-left: 2%;
        }

        .c3 {
            background-color: white;
            position: fixed;
            width: 400px;
            height: 300px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -200px;
            padding-top: 2%;
            padding-left: 2%;
        }

        #modal p {
            margin-left: 80px;
        }

        input::placeholder {
            color: #D0D0D0;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            工件解锁
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">

        <div id="citemList" class="aui-content">
            <div class="aui-form" id="citemForm">

            </div>
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">总成码</div>
                        <div class="aui-list-item-input">
                            <input id="barcode"></input>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label"  style="width: 50%;">下次加工工序</div>
                        <div class="aui-list-item-input"  onclick="goSelectOpCode()">
                            <input id="opCode" readonly></input>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">解锁原因</div>
                        <div class="aui-list-item-input" style="height: 100px;">
                            <input id="remark" style="height: 100px;" ></input>
                        </div>
                    </div>
                </li>
            </ul>

        </div>

    </div>
    <div class=' aui-btn aui-btn-info aui-btn-block' onclick='doSave()'>保存
    </div>
    <div style="width:100%;margin-top:2%;"></div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript">

    var routeCode = "";

    //初始化
    apiready = function () {

        $("#barcode").focus();
    };


    //产品条码监听回车事件
    $("#barcode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            doSerchBarCode()
        }
    });


    //查询总成码校验
    function doSerchBarCode() {
        var barcode = document.getElementById('barcode').value;

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSerchBarCodeUnlock";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                barcode: barcode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");

                if (map.code == '0') {
                    routeCode = map.routeCode;
                } else {
                    document.getElementById('barcode').value = "";
                    $("#barcode").focus();
                    api.toast({
                        msg: map.message,
                        duration: 3000
                    });
                }


            }

        });
    }



    //保存
    function doSave() {

        var barcode = document.getElementById('barcode').value;

        if (barcode == null || barcode == "") {

            api.toast({
                msg: "请先扫描产品条码！",
                duration: 3000
            });
            return
        }

        var opCode = document.getElementById('opCode').value;


        if (opCode == null || opCode == "") {

            api.toast({
                msg: "请先选择下次加工工序！",
                duration: 3000
            });
            return
        }


        var remark = document.getElementById('remark').value;

        if (remark == null || remark == "") {

            api.toast({
                msg: "请先填写解锁原因！",
                duration: 3000
            });
            return
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/barcodeUnlock";
        var data = {
            values: {
                remark: remark,
                barcode: barcode,
                opCode: opCode,
                un: un,
            }
        };

        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                console.log(ret);
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {
                    alert('保存成功！')
                    document.getElementById('barcode').value = "";
                    document.getElementById('opCode').value = "";
                    document.getElementById('remark').value = "";
                    $("#barcode").focus();


                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            }
        });


    }




    function setOpCode(id, code, name) {
        opid = id;
        opCode = code;
        opName = name;
        document.getElementById('opCode').value = code;
    }


    function goSelectOpCode() {

        var barcode = document.getElementById('barcode').value;
        if (barcode) {

            api.openWin({
                name: 'paOpCodeNext',
                url: 'paOpCodeNext.html',
                pageParam: {
                    routeCode:routeCode,
                    name: "barcodeUnlock",
                }
            });
        } else {
            $("#barcode").focus();
            api.toast({
                msg: "请先扫描总成码",
                duration: 3000
            });
        }
    }


    //返回按钮
    function closeWin() {
        // 
        if (api.pageParam.barcode == undefined) {
            api.closeWin({});
        } else {
            api.closeToWin({ name: api.pageParam.name });
            api.execScript({
                name: api.pageParam.name,
                script: 'refreshData()'
            });
        }
    }


</script>

</html>